package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.ExecutionSaleReq;
import net.hn.hnms.biz.plan.service.ExecutionSaleService;
import net.hn.hnms.biz.plan.vo.ExecutionSaleVo;
import net.hn.hnms.biz.plan.vo.SalesStatisticsVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 销量 
 *
 * @author zhaoyang
 * @date 2022-08-03
 */

@Api(value = "销量管理模块", tags = {"销量管理"})
@RestController
@RequestMapping("/execution/sale")
public class ExecutionSaleController extends BaseController {


    @Autowired
    private ExecutionSaleService executionSaleService;


    /**
     * 新增销量 
     */
    @ApiOperation("新增销量执行")
    @SaCheckPermission("execution:sale:add")
    @PostMapping("/add")
    @Log(title = "新增销量", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ExecutionSaleReq executionSaleReq) {
       return toAjax(executionSaleService.insert(executionSaleReq));
    }

    /**
     * 删除销量 
     */
    @ApiOperation("删除销量执行")
    @SaCheckPermission("execution:sale:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除销量", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        executionSaleService.deleteBatch(idList);
        return R.ok();
    }


    /**
     * 修改销量 
     */
    @ApiOperation("修改销量执行")
    @SaCheckPermission("execution:sale:update")
    @PutMapping("/update")
    @Log(title = "修改销量", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ExecutionSaleReq executionSaleReq) {
       executionSaleService.updateById(executionSaleReq);
        return R.ok();
    }


    /**
     * 启用/禁用
     */
    /*@ApiOperation("启用/禁用")
//    @SaCheckPermission("plan:sale:status:change")
    @PutMapping("/status/change/{id}/{status}")
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        executionSaleService.changeStatus(id, status);
        return R.ok();
    }*/

    /**
     * 获取销量 列表
     */
    @ApiOperation("获取销量 分页列表")
//    @SaCheckPermission("plan:sale:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ExecutionSaleVo>> page(ExecutionSaleReq executionSaleReq, PageQuery pageQuery) {
        return R.ok(executionSaleService.selectPageList(executionSaleReq, pageQuery));
    }


    /**
     * 获取销量 列表
     */
    @ApiOperation("获取销量 列表")
//    @SaCheckPermission("plan:sale:list")
    @GetMapping("/list")
    public R<List<ExecutionSaleVo>> list(ExecutionSaleReq executionSaleReq) {
        return R.ok(executionSaleService.selectList(executionSaleReq));
    }

    /**
     * 获取销量 详情
     */
    @ApiOperation("获取销量 详情")
//    @SaCheckPermission("plan:sale:detail")
    @GetMapping("/{id}")
    public R<ExecutionSaleVo> detail(@PathVariable("id") String id) {
        return R.ok(executionSaleService.selectDetailById(id));
    }


    @ApiOperation("高头窑运销统计")
    @GetMapping("/screen/transport")
    @AutoSetMineCode
    public R<SalesStatisticsVo> gtyTransportForBigScreen(ExecutionSaleReq req, String month) {
        return R.ok(executionSaleService.selectSalesStatisticsVo(req,month));
    }

}
